﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LoginModule.CongCu
{
    /// <summary>
    /// Lop nay dung de kiem tra tinh hop le cua dang ky don vi
    /// moi id truong chi duoc phep dang ky thanh lap don vi mot lan
    /// muon dang ky su dung buopc don vi phai co ma dang ky su dung
    /// </summary>
    public static class KiemTraTinhHopLe
    {
        // Ham kiem tra xem co ma so cua don vi chua moi cho dang ky tai khoan

        private static AccountModuleDataContext  acc = new AccountModuleDataContext();
        public static int kiemTraMaSo(int maso)
        {
            SOQUANLYDONVI tmpSoDonVi = acc.SOQUANLYDONVIs.SingleOrDefault(p => p.MASO == maso && p.DANGKYTAIKHOAN==false);
            int i=0;
            if (tmpSoDonVi != null) i = 1;

            return i;
        }

        // Xac nhan truong co id de dang ky thanh lap don vi

        public static int xacNhanTruongId(int matruong)
        {
            int have = 1;
            DOANSINH_CONGNHANTRUONG congNhan = acc.DOANSINH_CONGNHANTRUONGs.SingleOrDefault(p => p.ID == matruong);

            if (congNhan == null) have = 0;

            return have;
        }

        // Kiem tra ten tai khoan da ton tai hay chua
        public static int xacNhanTaiKhoanTonTai(string tenTaiKhoan)
        {
            int tonTai = 0;
            DANGKYSUDUNG taiKhoanKiemTra = acc.DANGKYSUDUNGs.SingleOrDefault(p => p.TENTAIKHOAN.ToUpper().Trim() == tenTaiKhoan.ToUpper().Trim());

            if (taiKhoanKiemTra != null) tonTai = 1;

            return tonTai;
        }
    }
}
